********************************************************************************************************
***** Multilevel regressions: Adding sectoral import growth at the employment level (Appendix C.10)*****
********************************************************************************************************
clear
use "BHPS_merged.dta"

do "ML programs to add model statistics.do"			


********************************************************************************
************************* Economic left-right attitudes ************************
********************************************************************************		

		global tradevar "real_gr_imp_CH_d_econ_nl"

	****************************** Economic left-right, full ***************
		polychoric econpol1 econpol2 econpol3 econpol4 econpol5 econpol6
		display r(sum_w)
		global N = r(sum_w)
		matrix r = r(R)
		factormat r, n($N) pcf
		predict econlr_full
		
		* create appropriate lags and deltas for Economic Left-Right analysis (t=2000, 2004 and 2007)
		gen LDVeconlr_full=L4.econlr_full if year==2004	
		replace LDVeconlr_full=L3.econlr_full if year==2007				
		
		gen D_econlr_full=econlr_full-L4.econlr_full if year==2004	
		replace D_econlr_full=econlr_full-L3.econlr_full if year==2007				
	
		* regression			
		mixed D_econlr_full c.LDVeconlr_full##i.year ///
					$tradevar ///
					$controls i.ID_NUTS1xYear  ///
					if (year==2004 | year==2007) ///
					|| ID_NUTS3: || ID_NUTS3xYear: , stddeviations 
	

	****************************** Economic policy *************************
		polychoric econpol3 econpol4 econpol5 econpol6
		display r(sum_w)
		global N = r(sum_w)
		matrix r = r(R)
		factormat r, n($N) pcf
		predict econlr_policy
		
		* create appropriate lags and deltas for Economic Left-Right analysis (t=2000, 2004 and 2007)
		gen LDVeconlr_policy=L4.econlr_policy if year==2004	
		replace LDVeconlr_policy=L3.econlr_policy if year==2007				
		
		gen D_econlr_policy=econlr_policy-L4.econlr_policy if year==2004	
		replace D_econlr_policy=econlr_policy-L3.econlr_policy if year==2007				
	
		* regression			
		mixed D_econlr_policy c.LDVeconlr_policy##i.year ///
					$tradevar ///
					$controls i.ID_NUTS1xYear  ///
					if (year==2004 | year==2007) ///
					|| ID_NUTS3: || ID_NUTS3xYear: , stddeviations 

		
	****************************** Economic injustice **********************
		polychoric econpol1 econpol2
		display r(sum_w)
		global N = r(sum_w)
		matrix r = r(R)
		factormat r, n($N) pcf
		predict econlr_injust
		
		* create appropriate lags and deltas for Economic Left-Right analysis (t=2000, 2004 and 2007)
		gen LDVeconlr_injust=L4.econlr_injust if year==2004	
		replace LDVeconlr_injust=L3.econlr_injust if year==2007				
		
		gen D_econlr_injust=econlr_injust-L4.econlr_injust if year==2004	
		replace D_econlr_injust=econlr_injust-L3.econlr_injust if year==2007				
	
		* regression			
		mixed D_econlr_injust c.LDVeconlr_injust##i.year ///
					$tradevar ///
					$controls i.ID_NUTS1xYear  ///
					if (year==2004 | year==2007) ///
					|| ID_NUTS3: || ID_NUTS3xYear: , stddeviations 

					
	****************************** Ownership *******************************
		polychoric econpol3 econpol4
		display r(sum_w)
		global N = r(sum_w)
		matrix r = r(R)
		factormat r, n($N) pcf
		predict econlr_owner
		
		* create appropriate lags and deltas for Economic Left-Right analysis (t=2000, 2004 and 2007)
		gen LDVeconlr_owner=L4.econlr_owner if year==2004	
		replace LDVeconlr_owner=L3.econlr_owner if year==2007				
		
		gen D_econlr_owner=econlr_owner-L4.econlr_owner if year==2004	
		replace D_econlr_owner=econlr_owner-L3.econlr_owner if year==2007				
	
		* regression			
		mixed D_econlr_owner c.LDVeconlr_owner##i.year ///
					$tradevar ///
					$controls i.ID_NUTS1xYear  ///
					if (year==2004 | year==2007) ///
					|| ID_NUTS3: || ID_NUTS3xYear: , stddeviations 
	
	
	***************** It is the government's responsibility to provide a job for everyone who wants one *********
		* create appropriate lags and deltas for Economic Left-Right analysis (t=2000, 2004 and 2007)
		gen LDVeconpol5=L4.econpol5 if year==2004	
		replace LDVeconpol5=L3.econpol5 if year==2007			
		
		gen D_econpol5=econpol5-LDVeconpol5
		mixed D_econpol5 c.LDVeconpol5##i.year  ///
							$tradevar ///
							$controls i.ID_NUTS1xYear  ///
							if (year==2004 | year==2007) ///
							|| ID_NUTS3: || ID_NUTS3xYear: , stddeviations
			
	
	***************** Strong trade unions are needed to protect the working conditions and wages of employees *********
		* create appropriate lags and deltas for Economic Left-Right analysis (t=2000, 2004 and 2007)
		gen LDVeconpol6=L4.econpol6 if year==2004	
		replace LDVeconpol6=L3.econpol6 if year==2007
	
		gen D_econpol6=econpol6-LDVeconpol6
		mixed D_econpol6 c.LDVeconpol6##i.year  ///
							$tradevar ///
							$controls i.ID_NUTS1xYear  ///
							if (year==2004 | year==2007) ///
							|| ID_NUTS3: || ID_NUTS3xYear: , stddeviations